package com.company.堆栈队列;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author Administrator
 */
public class AB3有效括号序列 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        AB3有效括号序列 ss = new AB3有效括号序列();
        boolean valid = ss.isValid(s);
        System.out.println(valid);
    }

    /**
     * @param s string字符串
     * @return bool布尔型
     */
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '(') {
                stack.push(')');
            } else if (chars[i] == '{') {
                stack.push('}');
            } else if (chars[i] == '[') {
                stack.push(']');
            } else if (stack.isEmpty() || stack.pop() != chars[i]) {
                return false;
            }
        }
        return stack.isEmpty();
    }
}
